<!-- 跟单-托管列表-->
<template>
  <div class="all">
    <list class="list" v-if="trusts.length > 1" :loadmoreoffset="50" @loadmore="httpTrustsLoading">
        
      <!--刷新-->
      <refresh class="refresh" @refresh="httpTrusts()" :display="isRefresh ? 'show' : 'hide'">
        <loading-indicator class="load text1"></loading-indicator>
      </refresh>

      <!--内容-->
      <cell v-for="(item, index) in trusts" v-bind:key="index">

        <VTrust class="cell" v-if="item.projectName" :item="item" @click="trustClick(item)"></VTrust>

        <div class="tipe" v-else>
          <text class="tipe-text font24 text3">{{T('跟单数据实时更新，历史表现不能代表未来收益；')}}</text>
          <text class="tipe-text font24 text3">{{T('年化收益率较低的数据将不会被展示在列表中；')}}</text>
          <text class="tipe-text font24 text3">{{T('市场有风险，投资需谨慎。')}}</text>
        </div>
      </cell>
    </list>

    <div class="empty bg2" v-else>
      <div class="empty-flex1"></div>
      <div class="acenter">
        <LImage class="empty-image" :src="Config.img('trust-empty.png')"></LImage>
      </div>
      <text class="font30 text1 empty-text">{{T('一键投入 躺赚收益 API托管 资金无忧')}}</text>

      <div class="height60"></div>
      <text class="font24 text2 empty-text">{{T('量化托管项目即将上线~~敬请期待~')}}</text>

      <div class="empty-flex2"></div>
      <text class="font30 text1 empty-text" @click="wxClick">{{T('团队入驻请联系Vtrading客服')}}</text>
    </div>
  </div>
</template>

<script>

//组件
import VTrust from '@/follw/view/VTrust.vue' 

//功能
import Config from "@/_js/config";
import navigator from "@/_js/navigator";
import modal from "@/_js/modal";
import math from "@/_js/math";

import weexHttp from "@/_js/https"; ;
const weexFunction = weex.requireModule("WeexFunction");

import I18N from "@/_i18n/i18n";
var T = I18N.t;

export default {

  components: {
    VTrust,
  },

  data() {
    return {
      Config:Config,
      T:T,
      math:math,

      pageNo:0, //页码
      pageMax:false, //turn最大页面
      
      isRefresh:false, //显示刷新
      isLoadinging:false, //显示加载

      trusts:[], //托管列表
    };
  },

  mounted() {
    this.httpTrusts();
  },
  
  methods: {
    
    initData(datas) {
      for (let index = 0; index < datas.length; index++) {
        var data = datas[index];
        var advanceSetting = data.advanceSetting;
        data.advanceSetting = advanceSetting;
        data.spotOrContract = advanceSetting.spotOrContract.length > 1;
        data.totalInvest = math.gfCoin(data.totalInvest, advanceSetting.symbol); 
        data.averageYearIncome = math.xiaoshu(data.averageYearIncome, 2, 2);
      }
      return datas;
    },

    /*************************************************通信触发*/
    //完全显示
    viewappear() {
    },

    /********************************** HTTP*/
    //托管列表-刷新
    httpTrusts() {
      if (this.isRefresh || this.isLoadinging) return;
      this.isRefresh = true;

      var param = {'pageNo':1};
      weexHttp.post("foundation/queryFundList",param, false,(data) => {
          this.isRefresh = false;

          if (data.status == 200) {
            data = data.data;

            this.trusts = this.initData(data);
            this.pageNo = 1;
            this.pageMax = data.length < 20;
            if(data.length < 20) this.trusts.push({});
          } else {
            modal.toast(data.msg);
          }
        }
      );
    },

    //托管列表-加载
    httpTrustsLoading() {
      if (this.pageMax || this.isRefresh || this.isLoadinging) return;
      this.isLoadinging = true;

      var param = {'pageNo': this.pageNo+1};
      weexHttp.post("foundation/queryFundList",param, false,(data) => {
        this.isLoadinging = false;

        if (data.status == 200) {
          data = data.data;

          var datas = this.initData(data);
          this.trusts.push(...datas);
          this.pageNo++;
          this.pageMax = datas.length < 20;
          if(datas.length < 20) this.trusts.push({});
        } else {
          modal.toast(data.msg);
        }
      });
    },

    /********************************** 点击触发*/
    //托管点击
    trustClick(item){
      
      weexFunction.getConfig("TrustProtocol",(value)=>{
        var param = {'teamProjectId':item.teamProjectId};
        if (value == 'true') {
          navigator.open('', "follw/UTrustInfo",param);
        } else {
          navigator.open('', "follw/UTrustProtocol",param);
        }
      });
    },

    //客服
    wxClick() {
      navigator.openDialog("mine/DialogWx");
    },
  },
};
</script>


<style src="@/_css/style.css"></style>
<style scoped>

/********************************************************************* 列表*/
.list {
  margin-top: 20px;
  flex: 1;
}
.cell {
  margin-top: 20px;
}

/*********************** 刷新*/
.refresh {
  width: 750;
  flex-direction: row;
  justify-content: center;
}
.load {
  margin-top: 16px;
  height: 40px;
  width: 40px;
}

/*********************** 提示*/
.tipe {
  margin-left: 60px;
  margin-right: 60px;
  margin-top: 40px;
  margin-bottom: 40px;
}
.tipe-text {
  line-height: 30px;
}


/*********************** 空白*/
.empty {
  flex: 1;

  padding-left: 40px;
  padding-right: 40px;
  padding-bottom: 40px;

  border-radius: 24px;

  margin-top: 20px;
  /* margin-top: 20px;
  margin-left: 20px;
  margin-right: 20px;
  margin-bottom: 30px; */
}
.empty-image-bg {
  align-items: center;
}
.empty-image {
  width: 433px;
  height: 283px;
  margin-bottom: 50px;
}
.empty-text {
  text-align: center;
}
.empty-but {
  justify-content: center;
  align-items: center;
  height: 96px;
  border-radius: 24px;
}
.empty-flex1 {
  flex: 1;
}
.empty-flex2 {
  flex: 2;
}
/*********************** 宽高*/
.height20{
  height: 20px;
}
.height60 {
  height: 60px;
}
</style>